package org.example.vo;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @Author：无敌暴龙战士
 * @Package：org.example.vo
 * @Project：learn_spring_security
 * @name：SecurityUse
 * @Date：2025/2/13 0:50
 * @Filename：SecurityUser
 * @Description:
 */
public class SecurityUser implements UserDetails {


    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        GrantedAuthority g1 = () -> "student:query"; //使用lambda表达式
//       GrantedAuthority g1=new SimpleGrantedAuthority("student:query");
        List<GrantedAuthority> grantedAuthorityList = new ArrayList<>();
        grantedAuthorityList.add(g1);
        return grantedAuthorityList;
    }

    @Override
    public String getPassword() {
        return new BCryptPasswordEncoder().encode("123456");
    }

    @Override
    public String getUsername() {
        return "thomas";
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
